function q=is_in_obstacle(pos,obs)
% is_in_obstacle: Test whether a position is in the specified obstacle object.
%
% SYNTAX:
%   ret = is_in_obstacle(pos,obs)
%   Return 1 if specified position pos lies in the obstacle obs or 0 if otherwise.
%   Obstacle object obs should be created with function NEWOBSTACLE.

%   Author: Hongbin Ma
%   Last updated: 2009-6-2 with MATLAB 6.5
%   Problems or suggestions? Email me: mathmhb[at]163.com

q=-1;
if isempty(pos)|isempty(obs),
    return;
end;

switch class(obs)
case 'struct'
    q=is_in_obs(pos,obs);
case 'cell'
    m=length(obs);
    for j=1:m,
        q=is_in_obs(pos,obs{j});
        if q>0,
            q=j;
            return;
        end;
    end;
    q=0;
end;

function q=is_in_obs(pos,obs)
q=-1;
if isempty(pos)|isempty(obs)|isempty(obs.nodes),
    return;
end;
in=inpoly(pos-obs.pos,obs.nodes);
q=in;
